package Classes.GameUtils
{
	import Classes.GameDatas.GD_Building_Func;
	import Classes.GameDatas.GD_Player;
	import Classes.GameDatas.GD_Weapon;
	import Classes.GameViews.ViewDisplayers.MapTargets.MT_Building;
	import Classes.GameViews.ViewPanels.VP_NewWeaponWin;
	import Classes.staticinfo.PlatformInfo;
	
	import UIComponents.FlatInfo;
	
	import flash.display.DisplayObject;
	import flash.system.ApplicationDomain;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Jul 17, 2012 3:53:17 PM 
	 */ 
	public class GU_dealWeapon
	{
		private static var _instance:GU_dealWeapon;
		private var weaponTx:String="weaponTx";
		private var mbdx:MT_Building;
		private static var txIcon:DisplayObject;
		private var button_sureY:Number=0;
		private var _weapon:GD_Weapon;
		
		public function GU_dealWeapon()	{}
		
		public static function get instance():GU_dealWeapon
		{
			if(!_instance)
			{
				_instance=new GU_dealWeapon();
				txIcon=new (ApplicationDomain.currentDomain.getDefinition("weaponTx") as Class);
			}
			return _instance;
		}
		
		public function hanldNewWeapon(weapon:GD_Weapon):void
		{
			if(!PlatformInfo.instance.isMoveScreen)
			{
				this._weapon=null;
				new VP_NewWeaponWin().setWeaponIc(weapon.icon,weapon.itemName+":"+weapon.description);
			}else{
				this._weapon=weapon;
			}
//			this.addTxToWeaponbuild();
		}
		
		public function playTxwin():void
		{
			if(null==this._weapon)return;
			new VP_NewWeaponWin().setWeaponIc(_weapon.icon,_weapon.itemName+":"+_weapon.description);
			this._weapon=null;
		}
		
		/**
		 * 给武器库加武器特效
		 */		
		public function addTxToWeaponbuild():void
		{
			mbdx=this.getMtView(40106001);
			
			if(null==mbdx)return;
			var ds:DisplayObject=mbdx.getChildByName(this.weaponTx);
			if(null==ds)
			{
				var dis:DisplayObject=mbdx.addChild(txIcon);
				dis.name=weaponTx;
				if(button_sureY==0)
				{
					button_sureY=dis.y-40;
				}
				dis.y=button_sureY;
			}
		}
		
		
		/**
		 * 移除特效 
		 */		
		public function removeTxToWeaponbuild():void
		{
			if(null==mbdx || null==mbdx.getChildByName(weaponTx))
			{
				return;
			}
			mbdx.removeChild(mbdx.getChildByName(weaponTx));
			//清空新的武器装载库
			GD_Player.instance.addNewWeapons=null;
			GD_Player.instance.addNewWeapons=new Object();
		}
		
		
		//独立的方法跟上面调用
		private function getMtView(zt_fun_id:Number):MT_Building
		{
			var mbdx:MT_Building
			if(GD_Player.instance.character.characterState==0 && GD_Player.instance.mapData)
			{
				for each (var gd2:GD_Building_Func in GD_Player.instance.mapData.buildingsObj)
				{
					if(gd2.buildingType==zt_fun_id)
					{
						mbdx=gd2.view;
						break;
					}
				}
			}
			return mbdx;
		}
		
		
	}
}
